package com.jhf.skypac_pda.db.helper;

import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;

import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.jhf.skypac_pda.adapter.MaterialtankfeedingorderListAdapter;
import com.jhf.skypac_pda.model.MaterialtankfeedingorderModel;

import java.util.Collections;
import java.util.List;

public class SimpleItemTouchHelperCallback extends ItemTouchHelper.Callback {

    private XRecyclerView xRecyclerView;
    private List<MaterialtankfeedingorderModel> mData;

    public SimpleItemTouchHelperCallback(XRecyclerView xRecyclerView, List<MaterialtankfeedingorderModel> mData) {
        this.xRecyclerView = xRecyclerView;
        this.mData = mData;
    }

    @Override
    public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
        int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
        int swipeFlags = ItemTouchHelper.START;
        return makeMovementFlags(dragFlags, swipeFlags);
    }

    @Override
    public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
        return false;
    }

    @Override
    public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
        int position = viewHolder.getAdapterPosition();
        mData.remove(position);
        ((MaterialtankfeedingorderListAdapter) xRecyclerView.getAdapter()).notifyItemRemoved(position);
    }

    @Override
    public boolean isLongPressDragEnabled() {
        return true;
    }

    @Override
    public boolean isItemViewSwipeEnabled() {
        return true;
    }
}


